package view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by eyesee on 2017/4/21.
 */

public class Slidingmenu extends ViewGroup{

    private View main;
    private View menu;
    private View menu2;

    public Slidingmenu(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**解析布局完成时调用*/
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        main = getChildAt(0);
//        menu = getChildAt(1);
//        menu2 = getChildAt(2);
    }

    /**测量
     * 如果是容器类(ViewGroup子类),不仅要测量自己的宽高,还要测量子view的宽高
     * */
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        //测量子view
        measureChildren(widthMeasureSpec,heightMeasureSpec);
    }

    /**设置子view位置*/
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        main.layout(-main.getMeasuredWidth(),t,0,b);

//        menu.layout(-menu.getMeasuredWidth(),t,0,b);
//        menu2.layout(-menu2.getMeasuredWidth(),t,0,b);
    }

    //处理事件的分发
    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {

        return false;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return super.onKeyDown(keyCode, event);
    }
}
